<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/27 17:54
 * Modified Time: 2019/7/27 17:54
 * Version: 2.0
 */

namespace App\Modules\Store\Repositories;


use App\Models\StorePaymentRoyalty;
use App\Modules\Store\Validators\StorePaymentRoyaltyValidator;
use Flower\Core\Repository\Eloquent\BaseRepository;

class StorePaymentRoyaltyRepository extends BaseRepository
{
    public function model()
    {
        return StorePaymentRoyalty::class;
    }

    public function validator()
    {
        return StorePaymentRoyaltyValidator::class;
    }

    /**
     * @param $store_id
     * @return mixed
     */
    public function newstoreCreatePaymentRoyalty($store_id)
    {
        $new_store_payment_royalty_data = [
            'store_id' => $store_id,
            'wechat' => '100',
            'alipay' => '100',
            'cash' => '100',
            'bank_card' => '100',
            'group_buy' => '100',
            'member_card' => '100',
        ];
        return $this->create($new_store_payment_royalty_data);
    }

    public function findByStoreId($storeId)
    {
        return $this->findByField('store_id', $storeId)->first();
    }

    public function updateStorePaymentRoyalty(
        $store_id, $wechat, $alipay, $cash, $bank_card, $group_buy, $member_card
    )
    {
        $store_payment_royalty = $this->model->where('store_id',$store_id)->first();
        $data = [];
        if($wechat){
            $data['wechat'] = $wechat;
        }
        if($alipay){
            $data['alipay'] = $alipay;
        }
        if($cash){
            $data['cash'] = $cash;
        }
        if($bank_card){
            $data['bank_card'] = $bank_card;
        }
        if($group_buy){
            $data['group_buy'] = $group_buy;
        }
        if($member_card){
            $data['member_card'] = $member_card;
        }
        return $this->update($data,$store_payment_royalty->id);
    }
}